package com.cuiyun97.controller.admin;


import com.cuiyun97.domain.dto.AdminDTO;
import com.cuiyun97.domain.dto.PageDTO;
import com.cuiyun97.domain.query.AdminQuery;
import com.cuiyun97.domain.vo.AdminVO;
import com.cuiyun97.result.Result;
import com.cuiyun97.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cyzz
 * @since 2024-12-06
 */
@Api(tags = "管理员操作接口")
@RestController
@RequestMapping("/admin/admin")
@RequiredArgsConstructor
@Slf4j
public class AdminController {

    private final IAdminService adminService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result queryPage(@ApiParam("查询条件") AdminQuery query) {
        log.info("分页查询管理员, 参数: {}", query);
        PageDTO<AdminVO> adminVOPageDTO = adminService.queryPage(query);
        return Result.success(adminVOPageDTO);
    }

    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Result queryById(@ApiParam("用户id") @PathVariable Integer id) {
        log.info("根据id查询管理员, id: {}", id);
        AdminVO adminVO = adminService.queryById(id);
        return Result.success(adminVO);
    }

    @ApiOperation("添加")
    @PostMapping
    public Result create(@ApiParam("用户实体") @RequestBody AdminDTO adminDTO) {
        adminService.create(adminDTO);
        return Result.success();
    }

    /**
     * 更新, 包含状态处理
     * @param adminDTO
     * @return
     */
    @ApiOperation("更新")
    @PutMapping
    public Result edit(@ApiParam("用户实体") @RequestBody AdminDTO adminDTO) {
        adminService.edit(adminDTO);
        return Result.success();
    }

    @ApiOperation("根据ids删除")
    @DeleteMapping
    public Result deleteByIds(@ApiParam("用户ids") @RequestParam List<Integer> ids) {
        adminService.deleteByIds(ids);
        return Result.success();
    }

}
